/*
 * Copyright (c) 2006-2018, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author            Notes
 * 2018-11-06     balanceTWK        change to new framework
 */

#ifndef __DRV_GPIO_H__
#define __DRV_GPIO_H__

#include <drv_common.h>

#define __GPIO_PORT(port)  GPIO##port

#define GET_PIN(PORTx,PIN) (rt_base_t)((16 * ( ((rt_base_t)__GPIO_PORT(PORTx) - (rt_base_t)GPIOA)/(0x0400UL) )) + PIN)

#define __GPIO_PIN(index, port, pin) {index,                    \
                                      RCC_APB2PERIPH_GPIO##port,\
                                      GPIO##port,               \
                                      GPIO_Pins_##pin,          \
                                      GPIO_PortSourceGPIO##port,\
                                      GPIO_PinsSource##pin }

/* GPIO driver */
struct pin_index
{
    int index;
    
    uint32_t clk;    
    GPIO_Type *gpio_periph;
    uint32_t pin;
    
    uint8_t port_src;
    uint8_t pin_src;    
};

struct pin_irq_map
{
    rt_uint16_t pinbit;
    IRQn_Type irqno;
};

int rt_hw_pin_init(void);

#endif /* __DRV_GPIO_H__ */

